package com.xjrsoft.module.ureport.controller;


import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.ureport.dto.ReportInfoDto;
import com.xjrsoft.module.ureport.service.IXjrReportInfoService;
import com.xjrsoft.module.ureport.vo.ReportInfoVo;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwq
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/report-info")
public class XjrReportInfoController {

    @Autowired
    private IXjrReportInfoService iXjrReportInfoService;
    
    @GetMapping("/tree")
    @ApiOperation("获取报表列表树")
    public Response tree() {
        return Response.ok(iXjrReportInfoService.tree());
    }

    @GetMapping("/{id}")
    @ApiOperation("获取报表文件详情")
    public Response getReportInfoById(@PathVariable String id) {
        return Response.ok(BeanUtil.copy(iXjrReportInfoService.getById(id), ReportInfoVo.class));
    }

    @PostMapping
    @ApiOperation("新增报表文件")
    public Response save(@RequestBody ReportInfoDto dto) {
        return Response.status(iXjrReportInfoService.saveReportInfo(dto));
    }

    @PutMapping("/{id}")
    @ApiOperation("修改报表文件")
    public Response updateRptRelation(@PathVariable String id, @RequestBody ReportInfoDto dto) {
        return Response.status(iXjrReportInfoService.updateReportInfo(id, dto));
    }

    @SneakyThrows
    @DeleteMapping("/{ids}")
    @ApiOperation("删除报表文件")
    public Response deleteRptRelation(@PathVariable String ids) {
        return Response.status(iXjrReportInfoService.deleteReportInfo(ids));
    }
}
